From: Priyanka Dhanda Date: Thu, 23 Dec 2010 23:12:31 +0000 (+0000) Subject: Some test cleanup. X-Git-Tag: 1.31.0-rc.0~33130 X-Git-Url: http://git.cyclocoop.org/%7D%7Cconcat%7B?a=commitdiff_plain;h=e6ad39cf5dbbb32d914189f25d4168bde3a3b9fe;p=lhc%2Fweb%2Fwiklou.git Some test cleanup. --- diff --git a/tests/selenium/SeleniumTestCase.php b/tests/selenium/SeleniumTestCase.php index 11e1b192ec..d1a5f4422e 100644 --- a/tests/selenium/SeleniumTestCase.php +++ b/tests/selenium/SeleniumTestCase.php @@ -1,4 +1,6 @@ assertRegExp( "/$text/", $innerHTML ); } -//Common Funtions Added for Selenium Tests - public function getExistingPage(){ - $this->open( $this->getUrl() . + /** + * Create a test fixture page if one does not exist + * @param $pageName The fixture page name. If none is supplied, it uses WIKI_INTERNAL_LINK + */ + function createTestPageIfMissing( $pageName = null ) { + if ( $pageName == null ) { + $pageName = WIKI_INTERNAL_LINK; + } + $this->type( INPUT_SEARCH_BOX, $pageName ); + $this->click( BUTTON_SEARCH ); + $this->waitForPageToLoad( WIKI_TEST_WAIT_TIME ); + $this->click( LINK_START . $pageName ); + $this->waitForPageToLoad( WIKI_TEST_WAIT_TIME ); + $location = $this->getLocation() . "\n"; + if ( strpos( $location, '&redlink=1') !== false ) { + $this->type( TEXT_EDITOR, "Test fixture page. No real content here" ); + $this->click( BUTTON_SAVE ); + $this->waitForPageToLoad( WIKI_TEST_WAIT_TIME ); + $this->assertTrue( $this->isTextPresent( $pageName ), + $this->getText( TEXT_PAGE_HEADING ) ); + } + } + + /** + * Create a test page using date as part of the name so that it is unique + * @param $pagePrefix The prefix to use for the page name. The current date will be appended to this to make it unique + * @param $watchThis Whether to add the page to my watchlist. Defaults to false. + */ + function createNewTestPage( $pagePrefix, $watchThis = false ) { + $pageName = $pagePrefix . date("Ymd-His"); + $this->type( INPUT_SEARCH_BOX, $pageName ); + $this->click( BUTTON_SEARCH ); + $this->waitForPageToLoad( WIKI_TEST_WAIT_TIME ); + $this->click( LINK_START . $pageName ); + $this->waitForPageToLoad( WIKI_TEST_WAIT_TIME ); + $location = $this->getLocation() . "\n"; + $this->assertContains( '&redlink=1', $location ). + $this->type( TEXT_EDITOR, "Test fixture page. No real content here" ); + if ( $watchThis ) { + $this->click( "wpWatchthis" ); + } + $this->click( BUTTON_SAVE ); + $this->waitForPageToLoad( WIKI_TEST_WAIT_TIME ); + $this->assertTrue( $this->isTextPresent( $pageName ), + $this->getText( TEXT_PAGE_HEADING ) ); + return $pageName; + } + + public function getExistingPage(){ + $this->open( $this->getUrl() . '/index.php?title=Main_Page&action=edit' ); - $this->type("searchInput", "new" ); - $this->click("searchGoButton"); - $this->waitForPageToLoad("30000"); - } + $this->type("searchInput", "new" ); + $this->click("searchGoButton"); + $this->waitForPageToLoad("30000"); + } - public function getNewPage($pageName){ + public function getNewPage($pageName){ - $this->open( $this->getUrl() . + $this->open( $this->getUrl() . '/index.php?title=Main_Page&action=edit' ); - $this->type("searchInput", $pageName ); - $this->click("searchGoButton"); - $this->waitForPageToLoad("30000"); - $this->click("link=".$pageName); - $this->waitForPageToLoad("600000"); + $this->type("searchInput", $pageName ); + $this->click("searchGoButton"); + $this->waitForPageToLoad("30000"); + $this->click("link=".$pageName); + $this->waitForPageToLoad("600000"); - } - // Loading the mediawiki editor - public function loadWikiEditor(){ - $this->open( $this->getUrl() . - '/index.php?title=Main_Page&action=edit' ); - } - - // Clear the content of the mediawiki editor - public function clearWikiEditor(){ - $this->type("wpTextbox1", ""); - } - - // Click on the 'Show preview' button of the mediawiki editor - public function clickShowPreviewBtn(){ - $this->click("wpPreview"); - } - - // Click on the 'Save Page' button of the mediawiki editor - public function clickSavePageBtn(){ - $this->click("wpSave"); - } - - // Click on the 'Edit' link - public function clickEditLink(){ - $this->click("link=Edit"); - $this->waitForPageToLoad("30000"); - } - - public function deletePage($pageName){ - $isLinkPresent = False; - $this->open( $this->getUrl() . + } + // Loading the mediawiki editor + public function loadWikiEditor(){ + $this->open( $this->getUrl() . '/index.php?title=Main_Page&action=edit' ); - $this->click("link=Log out"); - $this->waitForPageToLoad( "30000" ); - $this->click( "link=Log in / create account" ); - $this->waitForPageToLoad( "30000" ); - $this->type( "wpName1", "nadeesha" ); - $this->type( "wpPassword1", "12345" ); - $this->click( "wpLoginAttempt" ); - $this->waitForPageToLoad( "30000" ); - $this->type( "searchInput", $pageName ); - $this->click( "searchGoButton"); - $this->waitForPageToLoad( "30000" ); - - $this->click( "link=Delete" ); - $this->waitForPageToLoad( "30000" ); - $this->click( "wpConfirmB" ); - $this->waitForPageToLoad( "30000" ); - - } + } + + // Clear the content of the mediawiki editor + public function clearWikiEditor(){ + $this->type("wpTextbox1", ""); + } + // Click on the 'Show preview' button of the mediawiki editor + public function clickShowPreviewBtn(){ + $this->click("wpPreview"); + } + // Click on the 'Save Page' button of the mediawiki editor + public function clickSavePageBtn(){ + $this->click("wpSave"); + } + + // Click on the 'Edit' link + public function clickEditLink(){ + $this->click("link=Edit"); + $this->waitForPageToLoad("30000"); + } } diff --git a/tests/selenium/SeleniumTestConstants.php b/tests/selenium/SeleniumTestConstants.php new file mode 100644 index 0000000000..76af83761b --- /dev/null +++ b/tests/selenium/SeleniumTestConstants.php @@ -0,0 +1,20 @@ +setLoginBeforeTests( true ); - parent::setUp(); - } - public function addTests() { - $testFiles = array( - 'tests/selenium/suites/MyContributionsTestCase.php', - 'tests/selenium/suites/MyWatchListTestCase.php', - 'tests/selenium/suites/UserPreferencesTestCase.php', - 'tests/selenium/suites/MovePageTestCase.php', - 'tests/selenium/suites/PageSearchTestCase.php', - 'tests/selenium/suites/EmailPasswordTestCase.php', - 'tests/selenium/suites/CreateAccountTestCase.php' - ); - parent::addTestFiles( $testFiles ); - } + public function setUp() { + $this->setLoginBeforeTests( true ); + parent::setUp(); + } + public function addTests() { + $testFiles = array( + 'tests/selenium/suites/MyContributionsTestCase.php', + 'tests/selenium/suites/MyWatchListTestCase.php', + 'tests/selenium/suites/UserPreferencesTestCase.php', + 'tests/selenium/suites/MovePageTestCase.php', + 'tests/selenium/suites/PageSearchTestCase.php', + 'tests/selenium/suites/EmailPasswordTestCase.php', + 'tests/selenium/suites/CreateAccountTestCase.php' + ); + parent::addTestFiles( $testFiles ); + } } diff --git a/tests/selenium/suites/MyContributionsTestCase.php b/tests/selenium/suites/MyContributionsTestCase.php index fbbb542b3e..48873dc15d 100644 --- a/tests/selenium/suites/MyContributionsTestCase.php +++ b/tests/selenium/suites/MyContributionsTestCase.php @@ -32,45 +32,32 @@ class MyContributionsTestCase extends SeleniumTestCase { // Verify user contributions public function testRecentChangesAvailability() { - $newPage = "mypage999"; - $displayName = "Mypage999"; - - $this->open( $this->getUrl() . - '/index.php?title=Main_Page&action=edit' ); - - $this->type( "searchInput", $newPage); - $this->click( "searchGoButton" ); - $this->waitForPageToLoad( "60000" ); - $this->click( "link=".$displayName ); - $this->waitForPageToLoad( "600000" ); - $this->type( "wpTextbox1", $newPage." text" ); - $this->click( "wpSave" ); - $this->waitForPageToLoad( "60000" ); - + $newPage = $this->createNewTestPage( "MyContributionsTest" ); + // Verify My contributions Link available - $this->assertTrue($this->isElementPresent( "link=My contributions" )); + $this->assertTrue($this->isElementPresent( "link=Contributions" )); - $this->click( "link=My contributions" ); - $this->waitForPageToLoad( "30000" ); + + $this->click( "link=Contributions" ); + $this->waitForPageToLoad( WIKI_TEST_WAIT_TIME ); // Verify recent page adding available on My Contributions list - $this->assertEquals( $displayName, $this->getText( "link=".$displayName )); - - $this->type( "searchInput", $newPage ); - $this->click( "searchGoButton" ); - $this->waitForPageToLoad( "30000" ); - - $this->click( "link=Edit" ); - $this->waitForPageToLoad( "30000" ); - $this->type( "wpTextbox1", $newPage." text changed" ); - $this->click( "wpSave" ); - $this->waitForPageToLoad( "30000" ); - $this->click( "link=My contributions" ); - $this->waitForPageToLoad( "30000" ); + $this->assertEquals( $newPage, $this->getText( "link=".$newPage )); + + $this->type( INPUT_SEARCH_BOX, $newPage ); + $this->click( BUTTON_SEARCH ); + $this->waitForPageToLoad( WIKI_TEST_WAIT_TIME ); + + $this->click( LINK_EDIT ); + $this->waitForPageToLoad( WIKI_TEST_WAIT_TIME ); + $this->type( TEXT_EDITOR, $newPage . " text changed" ); + $this->click( BUTTON_SAVE ); + $this->waitForPageToLoad( WIKI_TEST_WAIT_TIME ); + $this->click( "link=Contributions" ); + $this->waitForPageToLoad( WIKI_TEST_WAIT_TIME ); // Verify recent page changes available on My Contributions - $this->assertTrue($this->isTextPresent($displayName." ‎ (top)")); - $this->deletePage($newPage); + $this->assertTrue( $this->isTextPresent( $newPage ) ); } } diff --git a/tests/selenium/suites/MyWatchListTestCase.php b/tests/selenium/suites/MyWatchListTestCase.php index b2cc326f26..aeaac3f300 100644 --- a/tests/selenium/suites/MyWatchListTestCase.php +++ b/tests/selenium/suites/MyWatchListTestCase.php @@ -33,41 +33,24 @@ class MyWatchListTestCase extends SeleniumTestCase { // Verify user watchlist public function testMyWatchlist() { - $newPage = "mypage"; - $displayName = "Mypage"; - $wikiText = "watch page"; - - $this->open( $this->getUrl().'/index.php?title=Main_Page' ); - - $this->type( "searchInput", $newPage ); - $this->click( "searchGoButton" ); - $this->waitForPageToLoad( "30000" ); - $this->click( "link=".$displayName ); - $this->waitForPageToLoad( "600000" ); - - $this->click( "wpWatchthis" ); - $this->type( "wpTextbox1",$wikiText ); - $this->click( "wpSave" ); - $this->waitForPageToLoad( "30000" ); - + $pageName = $this->createNewTestPage( "MyWatchListTest", true ); // Verify link 'My Watchlist' available - $this->assertTrue( $this->isElementPresent( "link=My watchlist" ) ); + $this->assertTrue( $this->isElementPresent( "link=Watchlist" ) ); - $this->click( "link=My watchlist" ); - $this->waitForPageToLoad( "30000" ); + $this->click( "link=Watchlist" ); + $this->waitForPageToLoad( WIKI_TEST_WAIT_TIME ); // Verify newly added page to the watchlist is available - $watchList = $this->getText( "//*[@id='bodyContent']" ); - $this->assertContains( $displayName, $watchList ); + $this->assertEquals( $pageName, $this->getText( "link=".$pageName )); - $this->type( "searchInput", $newPage ); - $this->click( "searchGoButton" ); - $this->waitForPageToLoad( "30000" ); - $this->click("link=Edit"); - $this->waitForPageToLoad( "30000" ); + $this->click( "link=".$pageName ); + $this->waitForPageToLoad( WIKI_TEST_WAIT_TIME ); + $this->click( LINK_EDIT ); + $this->waitForPageToLoad( WIKI_TEST_WAIT_TIME ); $this->click( "wpWatchthis" ); - $this->click( "wpSave" ); - $this->deletePage( $newPage ); + $this->click( BUTTON_SAVE ); + $this->assertFalse( $this->isElementPresent( "link=".$pageName ) ); + //todo watch using the dropdown menu } }